home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / iutil / getnuser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-18  |  1.1 KB  |  75 lines

  1. # include    <stdio.h>
  2. # include    <ingres.h>
  3. # include    <aux.h>
  4. # include    <sccs.h>
  5.  
  6. SCCSID(@(#)getnuser.c    8.1    12/31/84)
  7.  
  8. /*
  9. **  GETNUSER -- get line from user file based on name
  10. **
  11. **    Given a user name as a string, this routine returns the
  12. **    corresponding line from .../files/users into a buffer.
  13. **
  14. **    Parameters:
  15. **        name -- the name of the user
  16. **        buf -- a buf to dump the line in (declare as
  17. **            char buf[MAXLINE + 1]
  18. **
  19. **    Returns:
  20. **        zero -- success
  21. **        one -- failure (user not present)
  22. **
  23. **    Side effects:
  24. **        none
  25. **
  26. **    Files:
  27. **        .../files/users (readable)
  28. */
  29.  
  30. extern char *ztack();
  31.  
  32. getnuser(name, buf)
  33. char    *name;
  34. char    buf[];
  35. {
  36.     FILE        *userf;
  37.     register char    c;
  38.     register char    *bp;
  39.     
  40.     userf = fopen(ztack(Pathname, "/files/users"), "r");
  41.     if (userf == NULL)
  42.         syserr("getuser: open err");
  43.     
  44.     for (;;)
  45.     {
  46.         bp = buf;
  47.         while ((c = getc(userf)) != '\n')
  48.         {
  49.             if (c == EOF)
  50.             {
  51.                 fclose(userf);
  52.                 return (1);
  53.             }
  54.             *bp++ = c;
  55.         }
  56.         *bp++ = '\0';
  57.         bp = buf;
  58.         while ((c = *bp++) != ':')
  59.         {
  60.             if (c == '\0')
  61.             {
  62.                 fclose(userf);
  63.                 return (1);
  64.             }
  65.         }
  66.         *--bp = 0;
  67.         if (sequal(buf, name))
  68.         {
  69.             fclose(userf);
  70.             *bp = ':';
  71.             return (0);
  72.         }
  73.     }
  74. }
  75.